package com.zzu.base.scheduler.config;

import com.zzu.base.scheduler.job.MyQuartzJob;
import org.quartz.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class JobConfig {

    @Bean
    public JobDetail jobDetail() {
        return JobBuilder.newJob(MyQuartzJob.class)
                .withIdentity("myJob")//job名称
                // .withIdentity("myJob", "myGroup") // 可选：指定组名（name, group）
                // .storeDurably()                   // 可选：无触发器时是否保留任务
                .build();
    }

    @Bean
    public Trigger trigger() {
        return TriggerBuilder.newTrigger()
                .forJob(jobDetail())
                .withSchedule(CronScheduleBuilder.cronSchedule("0/1 * * * * ?")) // 每分钟执行一次
                // .withIdentity("myTrigger", "myGroup")  // 触发器唯一标识（可选）
                .build();
    }

}